package com.rx.mgt.dao;

import com.rx.mgt.dao.base.ManagementHibernateDaoBase;
import com.rx.mgt.domain.EmailListDomain;
import com.rx.mgt.po.UsersBo;
import org.apache.commons.lang.StringUtils;
import org.hibernate.Query;
import org.springframework.stereotype.Repository;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * Created by zxj on 2017/5/25.
 */
@Repository
public class EmailListDao extends ManagementHibernateDaoBase<EmailListDomain,Long> {
    @Transactional
    public List<EmailListDomain> findByDomain(UsersBo usersBo) {
        String hql  = " from EmailListDomain e where 1=1";
        if(StringUtils.isNotBlank(usersBo.getDomain())){
            hql = hql+" and e.domain =:domain";
        }
        Query query = template.getSessionFactory().getCurrentSession().createQuery(hql);
        if(StringUtils.isNotBlank(usersBo.getDomain())){
            query.setParameter("domain",usersBo.getDomain());
        }
        return query.list();
    }
}
